package practice.com0228;

import java.util.Arrays;

/**
 * 空字符串可被认为是有效字符串。
 * judgement判断
 * effective有效的
 */
public class Effective {

    public static void main(String[] args) {
        System.out.println(judgement(")()((((asd))))()"));
    }
    public static boolean judgement( String str ){

        char[] arr = str.toCharArray();
        System.out.println(Arrays.toString(arr));
        if (str.startsWith("(") == false && str.endsWith(")") == false) {
            System.out.println("无效括号");
            return false;
        }
        int count = 0;
        int count1 = 0;
        for (int i = 0; i < arr.length; i++) {
//            System.out.println(arr[i]);
            if (arr[i] == '(') {
                count += 1 ;
            }
            if (arr[i] == ')') {
                count1 += 1;
            }
        }
        if (count == count1) {
            System.out.println("有效方法");
            return true;
        }else {
            return false;
        }

    }

}
